package com.english.controller;

import com.english.entity.CustomerService;
import com.english.service.CustomerServiceService;
import com.english.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/customerService")
@CrossOrigin(origins = "*", allowCredentials = "false", maxAge = 3600)
public class CustomerServiceController {

    @Autowired
    private CustomerServiceService customerServiceService;

    /**
     * 获取客服联系方式
     */
    @GetMapping
    public R<CustomerService> getCustomerService() {
        try {
            CustomerService customerService = customerServiceService.getCustomerService();
            return R.success(customerService);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("获取客服信息失败：" + e.getMessage());
        }
    }

    /**
     * 更新客服联系方式
     */
    @PostMapping("/update")
    public R<String> updateCustomerService(@RequestBody CustomerService customerService) {
        try {
            boolean success = customerServiceService.updateCustomerService(customerService);
            if (success) {
                return R.success("更新成功");
            } else {
                return R.error("更新失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("更新失败：" + e.getMessage());
        }
    }
} 